//
//  ReusableHeaderView.m
//  Mango
//
//  Created by lanou3g on 16/5/11.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "ReusableHeaderView.h"


@interface ReusableHeaderView ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, copy) NSString *currentSkinModel;//夜间模式
@end

@implementation ReusableHeaderView

+ (instancetype)headerViewWithTableView:(UITableView *)tableView {
    static NSString *ID = @"header";
    ReusableHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:ID];
    if (header == nil) {
        header = [[ReusableHeaderView alloc]initWithReuseIdentifier:ID];
    }
    
    return header;
}


- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        self.titleLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.titleLabel];
        
        self.moreBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [self.moreBtn setTitle:@"更多" forState:(UIControlStateNormal)];
        [self.moreBtn setShowsTouchWhenHighlighted:YES];
       
        self.moreBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.moreBtn addTarget:self action:@selector(moreButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
        
        [self.contentView addSubview:self.moreBtn];
    }
    return self;
}

- (void)moreButtonAction {

    if ([self.delegate respondsToSelector:@selector(headerViewDidClickMoreBtn:)]) {
        [self.delegate headerViewDidClickMoreBtn:self.moreBtn.tag];
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.titleLabel.frame = CGRectMake(8, 0, 80, self.bounds.size.height);
    self.moreBtn.frame = CGRectMake(self.bounds.size.width - 50, 0, 50, self.bounds.size.height);
}

- (void)setTitle:(NSString *)title {
    if (_title != title) {
        _title = title;
        self.titleLabel.text = title;
    }
}


#pragma mark 切换至夜间模式
- (void)updateToNightSkinMode {
    self.contentView.backgroundColor = [UIColor colorWithRed:42/255.0 green:39/255.0 blue:43/255.0 alpha:1.0];
    self.titleLabel.textColor = [UIColor grayColor];
    [self.moreBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
}

-(void)updateToDaySkinMode {
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.titleLabel.textColor = [UIColor colorWithRed:252/255.0 green:65/255.0 blue:19/255.0 alpha:1.0];
    [self.moreBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
}

@end
